package edu.hawaii.myisern.model;

import java.util.Iterator;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertFalse;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;

//import org.junit.Test; 

/**
 * Tests operation of the StackModel instance. 
 * @author Philip Johnson
 * @author Ben Karsin
 */
public class TestMyIsernModel  {

  private static final String folder = "/.myisern/";
  private static final String home = "user.home";
  
  /**
   * Tests the MyIsernModel class.
   */
  @Test
  @SuppressWarnings( { "unchecked" } )
  public void testIsernModel() {
    MyIsernModel testModel = MyIsernModel.getInstance();
    CollaborationData collabData = new CollaborationData();
    OrganizationData orgData = new OrganizationData();
    ResearcherData resData = new ResearcherData();
    List<String> testList = new ArrayList<String>();
    List<List<String>> testData;
    String testString = "";
    Iterator testIter;
    Object testObject = new Object();
    
    assertSame("Checking instance identity", testModel, MyIsernModel.getInstance());

    orgData.loadData(System.getProperty(home) + folder);
    testData = orgData.getData();
    assertEquals("Organization data check", testData, testModel.getOrganizationData().getData());
    
    testList = collabData.getHeader();
    assertEquals("Collaboration Header data", testList.get(0), "Name");
    
    collabData.loadData(System.getProperty(home) + folder);
    testData = collabData.getData();
    assertEquals("Collaboration data check", testData, testModel.getCollaborationData().getData());
    
    testList = resData.getHeader();
    assertEquals("Researcher Header data", testList.get(0), "Name");
    
    resData.loadData(System.getProperty(home) + folder);
    testData = resData.getData();
    assertEquals("Researcher data check", testData, testModel.getResearcherData().getData());
    
    testList = testModel.getSemanticErrors();
    
    testModel.addHeader("TestHeader");
    testIter = testModel.headerIterator();
    
    while (testIter.hasNext()) {
      testString = testIter.next().toString();
    }
    assertEquals("Checking header was properly added.", testString, "TestHeader");
    
    testList = new ArrayList<String>();
    testList.add("TestData");
    testModel.addData(testList);
    testIter = testModel.dataIterator();
    
    while (testIter.hasNext()) {
      testObject = testIter.next();
    }
    testList = (List<String>)testObject;
    assertEquals("Checking that data was properly added", testList.get(0), "TestData");

    assertFalse("Checking model is not empty", testModel.isEmpty());
    
    assertEquals("Checking location of base folder", 
        testModel.getBaseFolder(), System.getProperty(home) + folder);
    
  }

}
